package com.projles;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.projles.util.Player;

public class AjudaActivity extends Activity implements OnClickListener{

	private int[] imgs;
	private LinearLayout layout;
	private Button btProx;
	private Button btAnte;
	private int ponteiro;
	
	private Player player;
	private String escolha;
	
	 @Override
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 setContentView(R.layout.ajuda);
		 
		 player = Player.getPlayer(this);
		 
		 Bundle params = getIntent().getExtras();
		 
		 escolha = (String) params.get("qual_jogo");
		 
		 
		 if (escolha.equals("cores")) {
			 imgs = new int[]{
					 R.drawable.inicial,
					 R.drawable.a, 
					 R.drawable.b, 
					 R.drawable.c,
					 R.drawable.d,
					 R.drawable.e};
		 }
		 else if (escolha.equals("animais")) {
			 imgs = new int[]{
					 R.drawable.inicial,
					 R.drawable.ia, 
					 R.drawable.ib, 
					 R.drawable.ic,
					 R.drawable.id,
					 R.drawable.d,
					 R.drawable.e};
		 }
		 
		 ponteiro = 0;
		 
		 
		 layout = (LinearLayout) findViewById(R.id.layout_ajuda);
		 layout.setBackgroundResource(imgs[ponteiro]);
		 
		 btProx = (Button) findViewById(R.id.bt_proxima);
		 btProx.setOnClickListener(this);
		 
		 btAnte = (Button) findViewById(R.id.bt_anterior);
		 btAnte.setOnClickListener(this);
		 btAnte.setEnabled(false);
	 }

	@Override
	public void onClick(View v) {
		player.click();
		 
		switch (v.getId()) {
		case R.id.bt_anterior:
			
			if (ponteiro != 0) {
				ponteiro--;
				btAnte.setEnabled(ponteiro != 0);
			}
			
			break;

		case R.id.bt_proxima:
			
			if (ponteiro != imgs.length-1) {
				ponteiro++;
				btAnte.setEnabled(true);
			}
			else {
				
				if (escolha.equals("cores")) {
					SharedPreferences.Editor editor = getSharedPreferences(OpcoesActivity.PREFS_NAME, 0).edit();
					editor.putBoolean("ja_usou_cores", true);
					editor.commit();
				}
				else if (escolha.equals("animais")) {
					SharedPreferences.Editor editor = getSharedPreferences(OpcoesActivity.PREFS_NAME, 0).edit();
			        editor.putBoolean("ja_usou_animais", true);
			        editor.commit();
				}
				
				finish();
			}
			
			break;
		}
		
		layout.setBackgroundResource(imgs[ponteiro]);
	}
	
	
}
